package com.zzh.mvvm.binding.internal;


import android.os.Looper;

import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * Created by zzh on 2023/11/1.
 *
 * @date: 2023/11/1 20:55
 * @email: zzh_hz@126.com
 * @author: zzh
 * @description: com.zzh.mvvm.binding.internal
 */
public class Preconditions {
    public static boolean checkMainThread(Observer<Object> observer) {
        if (Looper.myLooper() != Looper.getMainLooper()) {
            observer.onSubscribe(Disposable.empty());
            observer.onError(new IllegalStateException(
                    "Expected to be called on the main thread but was " + Thread.currentThread().getName()));
            return false;
        }
        return true;
    }
}
